package java_stack;

import java.util.ArrayList;
import java.util.List;

class Threadsafe {
    List<String> list = new ArrayList<>();
    public void method1(int loopNumber) {
        for (int i = 0; i < loopNumber; i++) {
            // 临界区，会产生竞态条件
            method2(list);
            method3(list);
        }
    }

    private void method2(List<String> list) {
        list.add("aa");
    }

    private void method3(List<String> list) {
        list.remove(0);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
           new Thread(()->{
               new Threadsafe().method1(1000);
           }).start();
        }
    }

}
